package net.uman.framework.modules.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import net.uman.framework.jms.PortalMessageProducer;
import net.uman.util.IPortalMessageConstants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PortalMessageHelper implements IPortalMessageConstants {
    private static Logger logger = LoggerFactory.getLogger(PortalMessageHelper.class);
//    @Autowired
//	private static PortalMessageProducer portalMessageProducer;

	public static boolean writePortalMessage(ArrayList<PortalMessageObject> msg) {
		if (msg == null) return false;
	    if (needsSending(msg)) {
	    	PortalMessageProducer portalMessageProducer = ApplicationContextProvider.getBean(PortalMessageProducer.class);
	    	portalMessageProducer.sendPortalMessage(msg);
	    	return true;
	    }else {
			return false;
		}
	}
	
	private static boolean needsSending(ArrayList<PortalMessageObject> obj) {	    
	    //if (typeMap == null) initializeMap();
	    if (portalMessages)
	    	return true;
	    else 
	    	return false;
	    
	}
	//是否发送短消息开关
	 private static boolean portalMessages=false;
	    public void setPortalMessages(boolean registable) {
	    	portalMessages = registable;
	}

	//	public void setMessageProducer(PortalMessageProducer portalMessageProducer) {
//	    this.portalMessageProducer = portalMessageProducer;
//	}
//	
	private static boolean enableOrderProcessPortalMsg=false;
    public void setEnableOrderProcessPortalMsg(boolean registable) {
        enableOrderProcessPortalMsg = registable;
    }
    
    private static boolean enableSettlementProcessPortalMsg=false;
    public void setEnableSettlementProcessPortalMsg(boolean registable) {
        enableSettlementProcessPortalMsg = registable;
    }
    
    private static boolean enableMainDataPortalMsg=false;
    public void setEnableMainDataPortalMsg(boolean registable) {
        enableMainDataPortalMsg = registable;
    }
    
    
    private static Map<Integer, Boolean> typeMap = null;
    
    private static synchronized void initializeMap() {
        typeMap = new HashMap<Integer, Boolean>();
        typeMap.put(Integer.valueOf(ORDER_PROCESS), Boolean.valueOf(enableOrderProcessPortalMsg));
        typeMap.put(Integer.valueOf(SETTLEMENT_PROCESS), Boolean.valueOf(enableSettlementProcessPortalMsg));
        typeMap.put(Integer.valueOf(MAIN_DATA), Boolean.valueOf(enableMainDataPortalMsg));
    }
}
